package com.eyolo.grpcclient.mq.listener;

import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;
import scwrapper.Sc;

/**
 * 超零铸币结果监听
 *
 * @author fanhailong
 * @date 2021/11/29 16:08
 **/
@Slf4j
@Component
@RocketMQMessageListener(topic = "${rocketmq.consumer.topicSCMint}",consumerGroup = "${rocketmq.consumer.scMintGroup}")
public class ScMintResultListener implements RocketMQListener<String> {


    @Override
    public void onMessage(String msg) {
        log.info("接收到超零铸币结果消息 {}", msg);
        try {
            Sc.OrderInfo.Builder builder = Sc.OrderInfo.newBuilder();
            JsonFormat.parser().ignoringUnknownFields().merge(msg, builder);
            Sc.OrderInfo orderInfo = builder.build();
            log.info("超零铸币消息 orderInfo:{}", orderInfo);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
    }

}
